//
//  AY_DetailContentCell.m
//  AiYue
//
//  Created by mac on 2023/10/24.
//

#import "AY_DetailContentCell.h"

@interface AY_DetailContentCell ()

@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UILabel *chapterLabel;
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation AY_DetailContentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        self.backgroundColor = COLOR(@"#F6F7FB");
        self.backView = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(13) andAddSubView:self.contentView];
        [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self.contentView).offset(YNUM(12));
            make.right.equalTo(self.contentView).offset(-YNUM(12));
            make.bottom.equalTo(self.contentView);
        }];
        
        self.chapterLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(18)] andLines:1 andRadius:0 andAddSubView:self.contentView];
        self.chapterLabel.textAlignment = NSTextAlignmentLeft;
        [self.chapterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backView).offset(YNUM(14));
            make.right.equalTo(self.backView).offset(-YNUM(5));
            make.top.equalTo(self.backView).offset(YNUM(18));
        }];
        
        self.contentLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:YFont(15) andLines:15 andRadius:0 andAddSubView:self.contentView];
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backView).offset(YNUM(16));
            make.right.equalTo(self.backView).offset(-YNUM(16));
            make.bottom.equalTo(self.backView).offset(-YNUM(52));
            make.top.equalTo(self.chapterLabel.mas_bottom).offset(YNUM(16));
        }];
        
        UIButton * goReadBtn = [AYTool createButtonWithFrame:CGRectZero andTitle:nil andFont:nil andTitleColor:nil andBg:nil andImage:YImage(@"icon_goread.png") andBgImage:nil andTarget:self andAction:@selector(goReadAction) andRadius:0 andAddSubView:self.backView];
        [goReadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.backView.mas_bottom).offset(YNUM(-12));
            make.centerX.equalTo(self.backView);
            make.height.mas_equalTo(YNUM(32));
            make.width.mas_equalTo(YNUM(96));
        }];
    }
    return self;
}

- (void)setBookModel:(BookModel *)bookModel {
    self.chapterLabel.text = bookModel.firstChapter.name;
    if (!kStringIsEmpty(bookModel.firstChapter.content)) {
        self.contentLabel.attributedText = [AYTool LineSpacingTextWithText:bookModel.firstChapter.content andSpace:YNUM(8)];
    }
}

- (void)goReadAction {
    if(self.goReadBlock) {
        self.goReadBlock();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
